package com.leetcode;

import com.leetcode.common.TreeNode;

/**
 * 226. 翻转二叉树
 * 先翻转当前节点再递归翻转子树
 *
 * @author fy
 * @date 2022-04-17 16:35
 */
public class Solution226_2 {

    public TreeNode invertTree(TreeNode root) {
        if (root == null) {
            return null;
        }
        // 先交换子节点
        TreeNode left = root.left;
        root.left = root.right;
        root.right = left;
        // 在递归翻转子树
        invertTree(root.left);
        invertTree(root.right);
        return root;
    }

}
